package com.controller;

import com.dto.BookDTO;
import com.dto.MemberDTO;
import com.service.LoginServiceImpl;
import com.service.MemberServiceImpl;
import com.util.Result;
import com.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 会员管理模块
 * @author linyukun
 * @date 2022/7/12 18:17
 */
@RequestMapping("member")
@RestController
public class MemberController {

    @Autowired
    private LoginServiceImpl loginServiceImpl;

    @Autowired
    private MemberServiceImpl memberServiceImpl;

    /**
     * 添加会员
     * @author linyukun
     * @date 2022-07-12
     */
    @RequestMapping(value="/addMember",method = RequestMethod.POST)
    public Result addMember(@RequestBody MemberDTO dto){
        try{
            String userName = loginServiceImpl.isLogin();
            return ResultUtil.returnDataSuccess(memberServiceImpl.addMember(dto));
        }catch(Exception e){
            e.printStackTrace();
            return ResultUtil.returnFailMsg(e.getMessage());
        }
    }

    /**
     * 修改会员
     * @author linyukun
     * @date 2022-07-12
     */
    @RequestMapping(value="/editMember",method = RequestMethod.POST)
    public Result editMember(@RequestBody MemberDTO dto){
        try{
            String userName = loginServiceImpl.isLogin();
            return ResultUtil.returnDataSuccess(memberServiceImpl.editMember(dto));
        }catch(Exception e){
            e.printStackTrace();
            return ResultUtil.returnFailMsg(e.getMessage());
        }
    }

    /**
     * 删除会员
     * @author linyukun
     * @date 2022-07-12
     */
    @RequestMapping(value="/delMember",method = RequestMethod.POST)
    public Result delMember(@RequestBody MemberDTO dto){
        try{
            String userName = loginServiceImpl.isLogin();
            return ResultUtil.returnDataSuccess(memberServiceImpl.delMember(dto));
        }catch(Exception e){
            e.printStackTrace();
            return ResultUtil.returnFailMsg(e.getMessage());
        }
    }

    /**
     * 获取会员通过id
     * @author linyukun
     * @date 2022-07-12
     */
    @RequestMapping(value="/getMemberById",method = RequestMethod.POST)
    public Result getMemberById(@RequestBody MemberDTO dto){
        try{
            String userName = loginServiceImpl.isLogin();
            return ResultUtil.returnDataSuccess(memberServiceImpl.getMemberById(dto));
        }catch(Exception e){
            e.printStackTrace();
            return ResultUtil.returnFailMsg(e.getMessage());
        }
    }

    /**
     * 获取会员列表
     * @author linyukun
     * @date 2022-07-12
     */
    @RequestMapping(value="/getMemberList",method = RequestMethod.POST)
    public Result getMemberList(@RequestBody MemberDTO dto){
        try{
            String userName = loginServiceImpl.isLogin();
            return ResultUtil.returnDataSuccess(memberServiceImpl.getMemberList(dto));
        }catch(Exception e){
            e.printStackTrace();
            return ResultUtil.returnFailMsg(e.getMessage());
        }
    }

    /**
     * 获取会员列表
     * @author linyukun
     * @date 2022-07-12
     */
    @RequestMapping(value="/getAdminMemberList",method = RequestMethod.POST)
    public Result getAdminMemberList(@RequestBody MemberDTO dto){
        try{
            String userName = loginServiceImpl.isLogin();
            return ResultUtil.returnDataSuccess(memberServiceImpl.getAdminMemberList(dto));
        }catch(Exception e){
            e.printStackTrace();
            return ResultUtil.returnFailMsg(e.getMessage());
        }
    }


    /**
     * 添加管理员
     * @author linyukun
     * @date 2022-07-12
     */
    @RequestMapping(value="/addAdmin",method = RequestMethod.POST)
    public Result addAdmin(@RequestBody MemberDTO dto){
        try{
            String userName = loginServiceImpl.isLogin();
            return ResultUtil.returnDataSuccess(memberServiceImpl.addAdmin(dto));
        }catch(Exception e){
            e.printStackTrace();
            return ResultUtil.returnFailMsg(e.getMessage());
        }
    }

    /**
     * 重置密码
     * @author linyukun
     * @date 2022-07-12
     */
    @RequestMapping(value="/resetAdminPassword",method = RequestMethod.POST)
    public Result resetAdminPassword(@RequestBody MemberDTO dto){
        try{
            String userName = loginServiceImpl.isLogin();
            return ResultUtil.returnDataSuccess(memberServiceImpl.resetAdminPassword(dto));
        }catch(Exception e){
            e.printStackTrace();
            return ResultUtil.returnFailMsg(e.getMessage());
        }
    }

}
